package net.frankish.moviebank2.front.model;

import java.util.Iterator;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import net.frankish.moviebank.beans.Movie;
import net.frankish.moviebank.util.Translator;

public class MovieListTableModel extends AbstractTableModel{

	private static final long serialVersionUID = 1L;
	Vector<Movie> movieList = null;
	public MovieListTableModel() {
		this(new Vector<Movie>());
	}
	public MovieListTableModel(Vector<Movie> data) {
		movieList = data;
	}
	
	public int getColumnCount() {
		return 3;
	}

	public int getRowCount() {
		return movieList.size();
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		switch(columnIndex){
			case 0: return movieList.get(rowIndex).getTitle();
			case 1:
				String genres = "";
				Iterator<String> it = movieList.get(rowIndex).getGenre().iterator();
				while(it.hasNext()){
					genres = genres+it.next() + (it.hasNext()?", ":"");
				}
				return genres;
			case 2: return movieList.get(rowIndex).getRelease();
		}
		return "";
	}
	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}
	@Override
	public String getColumnName(int column) {
		switch(column){
			case 0: return Translator.get(Translator.MOVIE_EDIT_LABEL_TITLE);
			case 1: return Translator.get(Translator.MOVIE_EDIT_LABEL_GENRE);
			case 2: return Translator.get(Translator.MOVIE_EDIT_LABEL_RELEASE);
		}
		return "";
	}
	
	
	
}
